package com.guanyu.u2cache.confinuelife;

import com.guanyu.u2cache.model.EventData;
import lombok.*;
import org.springframework.util.MethodInvoker;

import java.lang.reflect.Method;

/**
 * @author zhouyunjian
 * @date 2023/11/20 13:37
 * 注解类缓存，用于自动刷新缓存中的原始方法
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CachedInvocation {
    private EventData metaData;
    private Object targetBean;
    private Method targetMethod;
    private Object[] arguments;
    private Class returnType;


    @SneakyThrows
    public Object invoke() {
        final MethodInvoker invoker = new MethodInvoker();
        invoker.setTargetObject(this.getTargetBean());
        invoker.setArguments(this.getArguments());
        invoker.setTargetMethod(this.getTargetMethod().getName());
        invoker.prepare();
        return invoker.invoke();
    }
}
